package controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import model.User;
import model.UserDAO;

@ApplicationScoped
@ManagedBean
public class UsersBean {
	
	private User newUser = new User(); 

	private List<User> users = new ArrayList<User>();
	
	public UsersBean() {
		users = tests.PopulateData.populateUsersData();
		for (int i = 0; i < users.size(); i++) {
			UserDAO.addUser(users.get(i));
		}
	}
	
	public List<User> getUsers() {
		return UserDAO.list();
	}
	
	public void setUsers(List<User> users) {
		this.users = users;
	}
	
	public User getNewUser() {
		return newUser;
	}
	
	public void setNewUser(User newUser) {
		this.newUser = newUser;
	}
	
	public String getNewUserFirstname() {
		return newUser.getFirstname();
	}
	
	public void setNewUserFirstname( String newUserFirstName) {
		this.newUser.setFirstname(newUserFirstName);
	}
	
	public String getNewUserPatronymic() {
		return newUser.getPatronymic();
	}
	
	public void setNewUserPatronymic(String newUserPatronymic) {
		this.newUser.setPatronymic(newUserPatronymic);
	}
	
	public String getNewUserLastname() {
		return newUser.getLastname();
	}
	
	public void setNewUserLastname(String newUserLastName) {
		this.newUser.setLastname(newUserLastName);
	}
	
	public void add() {
		newUser.setKey((Long.valueOf(users.size())));
		users.add(newUser);
		UserDAO.addUser(newUser);
		System.out.print(newUser.getFullname());
	}
}
